package com.example.administrator.adroidtest;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016-12-27.
 */

public class WaveformlistDialog extends Dialog implements AdapterView.OnItemClickListener{

    private ArrayList<String> list=null;
    private Context context=null;
    private BaseAdapter myadapter=null;
    private onWaveformlistSelectListener onwaveformlistselectlistener;
    private ListView wavelistview;
    protected WaveformlistDialog(Context context,onWaveformlistSelectListener listener,ArrayList<String> list) {
        super(context);
        this.context=context;
        onwaveformlistselectlistener=listener;
        this.list=list;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.waveformlist);

        myadapter=new BaseAdapter() {
            @Override
            public int getCount() {
                return list.size();
            }

            @Override
            public Object getItem(int i) {
                return list.get(i);
            }

            @Override
            public long getItemId(int i) {
                return i;
            }

            @Override
            public View getView(int i, View view, ViewGroup viewGroup) {
                if(view==null){
                    LayoutInflater inflater=LayoutInflater.from(context);
                    view=inflater.inflate(R.layout.layout_general_item,null);
                }
                TextView textView=(TextView) view.findViewById(R.id.textView);
                textView.setText(list.get(i));
                return view;
            }

            public void AddAll(List newlist){

            notifyDataSetChanged();

            }
            public void remove(int i){
                list.remove(i);
                notifyDataSetChanged();
            }
        };

        wavelistview=(ListView) findViewById(R.id.wavelistview);
        wavelistview.setAdapter(myadapter);
        wavelistview.setOnItemClickListener(this);

    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
     if(onwaveformlistselectlistener!=null){
        onwaveformlistselectlistener.selectwaveformlist(list.get(i));
    }

    }



    public interface onWaveformlistSelectListener{
        void selectwaveformlist(String name);
    }

}
